// import './libs/mui.picker.min.js'
document.write("<script language='javascript' src='./components/libs/mui.picker.min.js'></script>")
document.write("<link rel='stylesheet' type='text/css' href='./components/libs/mui.picker.min.css'></link>")
if (Vue) {
    var template =
        '<div class="flexHC bgwhite padding15" >' +
        '<span class="font15 blue" @click="clickDateTimeStart">{{stDateTime}}</span>' +
        '<span class="font15 padding10">至</span>' +
        '<span class="font15 blue" @click="clickDateTimeEnd">{{endDateTime}}</span>' +
        '</div>'

    Vue.component('datetime', {
        template,
        data() {
            return {
                stDateTime: "0000000002",
                endDateTime: "0000000001",
            }
        },
        watch: {
            stDateTime(val) {
                this.stDateTime = val
            },
            endDateTime(val) {
                this.endDateTime = val
            }
        },
        methods: {
            pickerShow(val) {
                this.picker.show((rs) => {
                    if (val == 'start') {
                        this.stDateTime = rs.text
                    }
                    if (val == 'end') {
                        this.endDateTime = rs.text
                    }
                    console.log(val)
                    this.$emit('eventdata', val + "^" + rs.text)
                    this.picker.dispose()
                    this.picker = null
                })
            },
            selectDateTime(val) {
                if (this.picker) {
                    this.pickerShow(val)
                } else {
                    var optionsJson = '{}'
                    var options = JSON.parse(optionsJson)
                    this.picker = new mui.DtPicker(options)
                    this.pickerShow(val)
                }
            },
            clickDateTimeStart() {
                this.selectDateTime('start')
            },

            clickDateTimeEnd() {
                this.selectDateTime("end")
            }
        },
        mounted() {
            this.endDateTime = this.datetime
            this.stDateTime = this.endDateTime.substring(0, 10) + " 00:00"
        },
        props: {
            datetime: String
        },
    })
}
